/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facades;

import entities.CompanyAdquiredProfileFolder;
import entities.CompanyFolder;
import entities.CompanyFolderType;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author damfercer
 */
@Stateless
public class CompanyFolderFacade extends AbstractFacade<CompanyFolder> {
    @PersistenceContext(unitName = "ProyectoPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public CompanyFolderFacade() {
        super(CompanyFolder.class);
    }
    
    public List<CompanyFolder> find(Integer idCompany,Integer idCompanyFolderType){
        Query q=em.createNamedQuery("CompanyFolder.findByCompanyFolderTypeAndCompany",CompanyFolder.class);
        q.setParameter("idCompany", idCompany);
        q.setParameter("idCompanyFolderType", idCompanyFolderType);
        return q.getResultList();
    }
    
    public CompanyFolder findFolderWorkWithUs (Integer idCompany){
        List<CompanyFolder> companyFolderList =find(idCompany,new Integer("2"));
        CompanyFolder res = null;
        if(companyFolderList.size()==1){
            res= companyFolderList.get(0);
        }
        else if (companyFolderList.size()>1) {
            System.err.println("Hay más de una carpeta de tipo 2 en la compañía: "+idCompany.toString());
            res= companyFolderList.get(0);
        }
        return res;
        
    }
    
    
}
